package com.leoman.controller.api;

import com.leoman.core.ErrorType;
import com.leoman.core.bean.Result;
import com.leoman.entity.*;
import com.leoman.exception.*;
import com.leoman.service.*;
import com.leoman.utils.JsonUtil;
import com.leoman.utils.WebUtil;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.multipart.MultipartRequest;

import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 基本api
 * Created by 涂奕恒 on 2016/11/23 0018.
 */
@Controller
@RequestMapping(value = "api/index")
public class IndexApi {

    @Autowired
    private UserService userService;

    @Autowired
    private BannerService bannerService;

    @Autowired
    private ProvinceService provinceService;

    @Autowired
    private PromptService promptService;

    @Autowired
    private CommentService commentService;

    @Autowired
    private TagService tagService;

    @Autowired
    private LetterAnnexSampleService letterAnnexSampleService;

    @Autowired
    private SendPriceService sendPriceService;

    @Autowired
    private PaperImageService paperImageService;

    /**
     * @api {post} /api/index/sendCode 1、发送验证码
     * @apiVersion 0.0.1
     * @apiName index.sendCode
     * @apiGroup index
     *
     * @apiDescription 发送验证码
     *
     * @apiParam {String}   mobile      手机号                                                    (必填)
     * @apiParam {Integer}  type        验证码类型，1=注册，2=忘记密码，3=绑定手机号，默认为1          (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "code": 236541
     *      }
     * }
     */
    @RequestMapping(value = "/sendCode")
    public void sendCode(HttpServletResponse response, String mobile, Integer type) {
        try {
            String code = userService.sendCode(mobile, type);
            String result = JsonUtil.obj2ApiJson(Result.successInfoApi(code, "code"));
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (MobileExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MOBILE_EXIST));
        } catch (MobileNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MOBILE_NOT_FIND));
        }
    }

    /**
     * @api {post} /api/index/checkCodeStatus 2、检测验证码是否正确
     * @apiVersion 0.0.1
     * @apiName index.checkCodeStatus
     * @apiGroup index
     *
     * @apiDescription 检测验证码是否正确
     *
     * @apiParam {String}  mobile      手机号                                        (必填)
     * @apiParam {String}  code        验证码                                        (必填)
     * @apiParam {Integer} type        验证码类型，1=注册，2=忘记密码，3=绑定手机号，默认为1
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     * }
     */
    @RequestMapping(value = "/checkCodeStatus")
    public void checkCodeStatus(HttpServletResponse response, String mobile, String code, Integer type) {
        if (StringUtils.isBlank(mobile) || StringUtils.isBlank(code)) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
            return;
        }

        // 1=验证码不正确 2=验证码类型不正确 3=验证码超时
        Integer flag = userService.checkCode(mobile, code, type);
        switch (flag){
            case 0:
                WebUtil.printApi(response, Result.successApi());
                break;
            case 1:
                WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_CODE_ERROR));
                break;
            case 2:
                WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_CODE_TYPE_ERROR));
                break;
            case 3:
                WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_CODE_OUT_TIME));
                break;
            default:
                WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_BASE));
                break;
        }
    }

    /**
     * @api {post} /api/index/register 3、注册
     * @apiVersion 0.0.1
     * @apiName index.register
     * @apiGroup index
     *
     * @apiDescription 注册
     *
     * @apiParam {String}   mobile                      手机号         (必填)
     * @apiParam {String}   password                    密码           (必填)
     * @apiParam {String}   code                        验证码         (必填)
     *
     * @apiSuccess {Object}   userInfo
     * @apiSuccess {Integer}  userInfo.id               id
     * @apiSuccess {String}   userInfo.nickName         昵称
     * @apiSuccess {String}   userInfo.avatar           头像
     * @apiSuccess {String}   userInfo.backgroundImage  背景图
     * @apiSuccess {String}   userInfo.birthday         生日
     * @apiSuccess {String}   userInfo.mobile           手机
     * @apiSuccess {Integer}  userInfo.sex              性别
     * @apiSuccess {Integer}  userInfo.regionId         所在区域ID
     * @apiSuccess {Integer}  userInfo.regionInfo       所在区域名称
     * @apiSuccess {Integer}  userInfo.money            账户余额
     * @apiSuccess {String}   userInfo.createTime       注册时间
     * @apiSuccess {String}   userInfo.updateTime       修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "userInfo": {
     *              "id": 14,
     *              "nickName": "老大",
     *              "avatar": "",
     *              "backgroundImage": "",
     *              "birthday": "",
     *              "mobile": "13872116519",
     *              "sex": 0,
     *              "regionId": "",
     *              "regionInfo": "",
     *              "money": 0.0,
     *              "createTime": "1474600084564",
     *              "updateTime": "1474600084564"
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/register", method = RequestMethod.POST)
    public void register(HttpServletResponse response, String mobile, String password, String code) {
        try {
            User user = userService.iRegister(mobile, password, code);
            String result = JsonUtil.obj2ApiJson(Result.successInfoApi(user, "userInfo"), "password", "type", "region", "sealStatus");
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (MobileExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MOBILE_EXIST));
        } catch (CodeErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_CODE_ERROR));
        }
    }

    /**
     * @api {post} /api/index/login 4、登录
     * @apiVersion 0.0.1
     * @apiName index.login
     * @apiGroup index
     *
     * @apiDescription 登录
     *
     * @apiParam   {String}   mobile                    手机号         (必填)
     * @apiParam   {String}   password                  密码           (必填)
     *
     * @apiSuccess {Object}   userInfo
     * @apiSuccess {Integer}  userInfo.id               id
     * @apiSuccess {String}   userInfo.nickName         昵称
     * @apiSuccess {String}   userInfo.avatar           头像
     * @apiSuccess {String}   userInfo.backgroundImage  背景图
     * @apiSuccess {String}   userInfo.birthday         生日
     * @apiSuccess {String}   userInfo.mobile           手机
     * @apiSuccess {Integer}  userInfo.sex              性别
     * @apiSuccess {Integer}  userInfo.regionId         所在区域ID
     * @apiSuccess {Integer}  userInfo.regionInfo       所在区域名称
     * @apiSuccess {Integer}  userInfo.money            账户余额
     * @apiSuccess {String}   userInfo.createTime       注册时间
     * @apiSuccess {String}   userInfo.updateTime       修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "userInfo": {
     *              "id": 14,
     *              "nickName": "老大",
     *              "avatar": "",
     *              "backgroundImage": "",
     *              "birthday": "",
     *              "mobile": "13872116519",
     *              "sex": 0,
     *              "regionId": "",
     *              "regionInfo": "",
     *              "money": 0.0,
     *              "createTime": "1474600084564",
     *              "updateTime": "1474600084564"
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public void login(HttpServletResponse response, String mobile, String password) {
        try {
            User user = userService.iUserLogin(mobile, password);
            String result = JsonUtil.obj2ApiJson(Result.successInfoApi(user, "userInfo"), "password", "type", "region", "sealStatus");
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (MobileNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MOBILE_NOT_FIND));
        } catch (PasswordErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_PASSWORD_ERROR));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/index/loginPlus 5、第三方登录
     * @apiVersion 0.0.1
     * @apiName index.loginPlus
     * @apiGroup index
     *
     * @apiDescription 第三方登录
     *
     * @apiParam {String}     openId                    唯一标识                                (必填)
     * @apiParam {Integer}    type                      类型，1=QQ，2=微信，3=微博               (必填)
     * @apiParam {String}     avatar                    头像
     * @apiParam {String}     nickName                  昵称
     * @apiParam {Integer}    sex                       性别，0=男，1=女
     *
     * @apiSuccess {Object}   userInfo
     * @apiSuccess {Integer}  userInfo.id               id
     * @apiSuccess {String}   userInfo.nickName         昵称
     * @apiSuccess {String}   userInfo.avatar           头像
     * @apiSuccess {String}   userInfo.backgroundImage  背景图
     * @apiSuccess {String}   userInfo.birthday         生日
     * @apiSuccess {String}   userInfo.mobile           手机
     * @apiSuccess {Integer}  userInfo.sex              性别
     * @apiSuccess {Integer}  userInfo.regionId         所在区域ID
     * @apiSuccess {Integer}  userInfo.money            账户余额
     * @apiSuccess {String}   userInfo.createTime       注册时间
     * @apiSuccess {String}   userInfo.updateTime       修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "userInfo": {
     *              "id": 14,
     *              "nickName": "老大",
     *              "avatar": "",
     *              "backgroundImage": "",
     *              "birthday": "",
     *              "mobile": "13872116519",
     *              "sex": 0,
     *              "regionId": "",
     *              "money": 0.0,
     *              "createTime": "1474600084564",
     *              "updateTime": "1474600084564"
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/loginPlus", method = RequestMethod.POST)
    public void loginPlus(HttpServletResponse response, String openId, Integer type, String avatar, String nickName, Integer sex) {
        try {
            User user = userService.iLoginPlus(openId, type, avatar, nickName, sex);
            String result = JsonUtil.obj2ApiJson(Result.successInfoApi(user, "userInfo"), "password", "type", "region", "sealStatus");
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (ThirdTypeErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_THIRD_TYPE_ERROR));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/index/forgetPwd 6、忘记密码
     * @apiVersion 0.0.1
     * @apiName index.forgetPwd
     * @apiGroup index
     *
     * @apiDescription 忘记密码
     *
     * @apiParam {String}   mobile                    手机号              (必填)
     * @apiParam {String}   password                  密码                (必填)
     * @apiParam {String}   code                      验证码              (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     * }
     */
    @RequestMapping(value = "/forgetPwd", method = RequestMethod.POST)
    public void forgetPwd(HttpServletResponse response, String mobile, String password, String code) {
        try {
            userService.iForgetPwd(mobile, password, code);
            String result = JsonUtil.obj2ApiJson(Result.successApi());
            WebUtil.printApi(response, result);
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (MobileNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MOBILE_NOT_FIND));
        } catch (CodeErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_CODE_ERROR));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/index/bindingMobile 7、绑定手机号
     * @apiVersion 0.0.1
     * @apiName index.bindingMobile
     * @apiGroup index
     *
     * @apiDescription 绑定手机号
     *
     * @apiParam {Integer}  userId                    用户ID              (必填)
     * @apiParam {String}   mobile                    手机号              (必填)
     * @apiParam {String}   password                  密码                (必填)
     * @apiParam {String}   code                      验证码              (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     * }
     */
    @RequestMapping(value = "/bindingMobile", method = RequestMethod.POST)
    public void bindingMobile(HttpServletResponse response, Integer userId, String mobile, String password, String code) {
        try {
            userService.iBindingMobile(userId, mobile, password, code);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (MobileExistException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MOBILE_EXIST));
        } catch (CodeErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_CODE_ERROR));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/index/listBanner 8、首页banner图列表
     * @apiVersion 0.0.1
     * @apiName index.listBanner
     * @apiGroup index
     *
     * @apiDescription 首页banner图列表
     *
     * @apiSuccess {Object}   list
     * @apiSuccess {Integer}  list.id               banner图ID
     * @apiSuccess {Integer}  list.type             类型，1=草丛banner，2=其他banner
     * @apiSuccess {Integer}  list.position         位置，1=纸条，2=广播，3=心事，4=草丛，5=登录图片，6=信天涯
     * @apiSuccess {String}   list.url              图片地址
     * @apiSuccess {String}   list.updateTime       修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "type" : 1,
     *                  "position" : 1,
     *                  "url" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "updateTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/listBanner", method = RequestMethod.POST)
    public void listBanner(HttpServletResponse response) {
        List<Banner> list = bannerService.iFindList();
        String result = JsonUtil.obj2ApiJson(Result.successListApi(list));
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/prompt 9、文字提示
     * @apiVersion 0.0.1
     * @apiName index.prompt
     * @apiGroup index
     *
     * @apiDescription 文字提示
     *
     * @apiSuccess {Object}   list
     * @apiSuccess {Integer}  list.id               文字提示ID
     * @apiSuccess {Integer}  list.type             类型，0=信件，1=纸条，2=广播，3=心事，4=兴趣圈
     * @apiSuccess {String}   list.content          内容
     * @apiSuccess {String}   list.updateTime       修改时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "type" : 1,
     *                  "content" : "让您的信件与众不同",
     *                  "updateTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/prompt", method = RequestMethod.POST)
    public void prompt(HttpServletResponse response) {
        List<Prompt> list = promptService.findAll();
        String result = JsonUtil.obj2ApiJson(Result.successListApi(list));
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/addFeedBack 10、添加意见反馈
     * @apiVersion 0.0.1
     * @apiName index.addFeedBack
     * @apiGroup index
     *
     * @apiDescription 添加意见反馈
     *
     * @apiParam {Integer}  userId                    用户ID              (必填)
     * @apiParam {String}   mobile                    手机号
     * @apiParam {String}   content                   反馈内容            (必填)
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     * }
     */
    @RequestMapping(value = "/addFeedBack", method = RequestMethod.POST)
    public void addFeedBack(HttpServletResponse response, Integer userId, String mobile, String content) {
        try {
            if (StringUtils.isBlank(content)) {
                WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
                return;
            }
            userService.iAddFeedBack(userId, mobile, content);
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.successApi()));
        } catch (ParamErrorException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_NOT_PARAM));
        } catch (UserNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_NOT_FIND));
        } catch (MobileNotFindException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_MOBILE_NOT_FIND));
        } catch (UserSealStatusException e) {
            WebUtil.printApi(response, Result.failureApi(ErrorType.ERROR_USER_STATUS_DISABLED));
        }
    }

    /**
     * @api {post} /api/index/listProvince 11、省市区列表
     * @apiVersion 0.0.1
     * @apiName index.listProvince
     * @apiGroup index
     *
     * @apiDescription 省市区列表
     *
     * @apiSuccess {Object}   list                                省份列表
     * @apiSuccess {Integer}  list.id                             省份id
     * @apiSuccess {String}   list.name                           省份名称
     * @apiSuccess {Object}   list.cityList                       城市列表
     * @apiSuccess {Integer}  list.cityList.id                    城市id
     * @apiSuccess {String}   list.cityList.name                  城市名称
     * @apiSuccess {Object}   list.cityList.regionList            区域列表
     * @apiSuccess {Integer}  list.cityList.regionList.id         区域id
     * @apiSuccess {String}   list.cityList.regionList.name       区域名称
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "name" : "北京",
     *                  "cityList" : [
     *                      {
     *                          "id" : 1,
     *                          "name" : "北京市",
     *                          "regionList" : [
     *                              {
     *                                  "id" : 1,
     *                                  "name" : "东城区"
     *                              },
     *                              {
     *                                  "id" : 2,
     *                                  "name" : "西城区"
     *                              }
     *                          ]
     *                      }
     *                  ]
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/listProvince", method = RequestMethod.POST)
    public void listProvince(HttpServletResponse response) {
        List<Province> list = provinceService.findList();
        String result = JsonUtil.obj2ApiJson(Result.successListApi(list), "province", "city", "region");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/listTag 12、标签列表
     * @apiVersion 0.0.1
     * @apiName index.listTag
     * @apiGroup index
     *
     * @apiDescription 标签列表
     *
     * @apiSuccess {Object}   list                                标签列表
     * @apiSuccess {Integer}  list.id                             标签id
     * @apiSuccess {String}   list.content                        标签
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "content" : "鲜花"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/listTag", method = RequestMethod.POST)
    public void listTag(HttpServletResponse response) {
        List<Tag> list = tagService.findAll();
        String result = JsonUtil.obj2ApiJson(Result.successListApi(list), "createTime", "updateTime");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/commentList 13、评论列表
     * @apiVersion 0.0.1
     * @apiName index.commentList
     * @apiGroup index
     *
     * @apiDescription 纸条列表
     *
     * @apiParam   {Integer}   sourceId                   目标ID
     * @apiParam   {Integer}   sourceType                 目标类型，0=信件，1=纸条，2=广播，3=心事，4=兴趣圈，7=黑板
     * @apiParam   {Integer}   userId                     用户Id
     * @apiParam   {Integer}   type                       类型，1，我发送的评论 2，别人对我的评论
     * @apiParam   {Integer}   pageNum                    页码
     * @apiParam   {Integer}   pageSize                   每页显示条数
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    评论ID
     * @apiSuccess {Integer}   list.sourceType            目标类型，0=信件，1=纸条，2=广播，3=心事，4=兴趣圈，7=黑板
     * @apiSuccess {Integer}   list.isReply               是否回复，0=否，不为0=回复用户ID
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {String}    list.voiceUrl              语音URL
     * @apiSuccess {Integer}   list.voiceTime             语音长度
     * @apiSuccess {Integer}   list.isAdmin               是否管理员发送，0=否，1=是
     * @apiSuccess {Integer}   list.isTop                 是否置顶，0=否，1=是
     * @apiSuccess {Integer}   list.cover                 评论目标封面
     * @apiSuccess {String}    list.title                 评论目标标题
     * @apiSuccess {String}    list.synopsis              评论目标简介
     * @apiSuccess {String}    list.userId                评论人ID
     * @apiSuccess {String}    list.nickName              评论人昵称
     * @apiSuccess {String}    list.toUserNickName        回复用户昵称
     * @apiSuccess {String}    list.avatar                评论人头像
     * @apiSuccess {String}    list.imageList             图片列表
     * @apiSuccess {String}    list.imageList.id          图片ID
     * @apiSuccess {String}    list.imageList.url         图片url
     * @apiSuccess {String}    list.createTime            评论时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "sourceType" : 1,
     *                  "isReply" : 0,
     *                  "content" : "我是一只萌萌哒小兔子，我生长在美丽的帕斯米尔大草原，我从小就喜欢吃青草",
     *                  "voiceUrl" : "http://4.16.3.22:8080/images/cover.mp3",
     *                  "voiceTime" : 0,
     *                  "isAdmin" : 0,
     *                  "isTop" : 1,
     *                  "cover" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "title" : "",
     *                  "synopsis" : "",
     *                  "userId" : 1,
     *                  "nickName" : "张三",
     *                  "toUserNickName" : "",
     *                  "avatar" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "imageList" : [
     *                      {
     *                          "id" : 1,
     *                          "url" : "http://4.16.3.22:8080/images/cover.jpg"
     *                      }
     *                  ],
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/commentList", method = RequestMethod.POST)
    public void commentList(HttpServletResponse response, Integer sourceId, Integer sourceType, Integer userId, Integer type, Integer pageNum, Integer pageSize) {
        Page<Comment> page = commentService.iPageForApp(sourceId, sourceType, userId, type, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "user", "sourceUser", "sourceId");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/letterAnnexList 14、物品列表
     * @apiVersion 0.0.1
     * @apiName index.letterAnnexList
     * @apiGroup index
     *
     * @apiDescription 物品列表
     *
     * @apiParam   {Integer}   letterAnnexId              物品id
     * @apiParam   {Integer}   type                       类型，1=信纸，2=信封，3=邮票
     * @apiParam   {Integer}   pageNum                    页码                         （必填）
     * @apiParam   {Integer}   pageSize                   每页显示条数                  （必填）
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    物品ID
     * @apiSuccess {Integer}   list.type                  类型，1=信纸，2=信封，3=邮票
     * @apiSuccess {String}    list.cover                 封面url
     * @apiSuccess {String}    list.content               内容
     * @apiSuccess {String}    list.name                  物品名称
     * @apiSuccess {String}    list.num                   物品编号
     * @apiSuccess {String}    list.money                 价格
     * @apiSuccess {String}    list.description           物品描述
     * @apiSuccess {String}    list.createTime            创建时间
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "page": {
     *              "totalNum": 0,
     *              "totalPage": 0,
     *              "currentPage": 1
     *          },
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "type" : 1,
     *                  "cover" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "content" : "我是一只萌萌哒小兔子，我生长在美丽的帕斯米尔大草原，我从小就喜欢吃青草",
     *                  "name" : "测试数据",
     *                  "num" : "512-259",
     *                  "money" : 1.5,
     *                  "description" : "",
     *                  "createTime" : "1476843673494"
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/letterAnnexList", method = RequestMethod.POST)
    public void letterAnnexList(HttpServletResponse response, Integer letterAnnexId, Integer type, Integer pageNum, Integer pageSize) {
        Page<LetterAnnexSample> page = letterAnnexSampleService.iPageByParams(letterAnnexId, type, pageNum, pageSize);
        Map<String, Object> dataMap = JsonUtil.fitting(page);
        String result = JsonUtil.obj2ApiJson(Result.successApi(dataMap), "letterAnnexId");
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/updateVersion 15、更新版本
     * @apiVersion 0.0.1
     * @apiName index.updateVersion
     * @apiGroup index
     *
     * @apiDescription 更新版本
     *
     * @apiParam {String}   num                    版本号
     * @apiParam {Stream}   apk                    apk文件
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {}
     * }
     */
    @RequestMapping(value = "/updateVersion", method = RequestMethod.POST)
    public void updateVersion(HttpServletResponse response, String num, MultipartRequest multipartRequest) {
        userService.iUpdateVersion(num, multipartRequest);
        String result = JsonUtil.obj2ApiJson(Result.successApi());
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/checkVersion 16、比对版本
     * @apiVersion 0.0.1
     * @apiName index.checkVersion
     * @apiGroup index
     *
     * @apiDescription 比对版本
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "versionInfo" : {
     *              "num" : 1,
     *              "url" : "http://www.qq.com"
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/checkVersion", method = RequestMethod.POST)
    public void checkVersion(HttpServletResponse response) {
        String result = JsonUtil.obj2ApiJson(Result.successInfoApi(userService.iCheckVersion(), "versionInfo"));
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/priceInfo 17、寄信价格查询
     * @apiVersion 0.0.1
     * @apiName index.priceInfo
     * @apiGroup index
     *
     * @apiDescription 寄信价格查询
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status": 0,
     *      "msg": "",
     *      "data": {
     *          "priceInfo" : {
     *              "money1" : 1.5,
     *              "money2" : 3
     *          }
     *      }
     * }
     */
    @RequestMapping(value = "/priceInfo", method = RequestMethod.POST)
    public void priceInfo(HttpServletResponse response) {
        Map<String, Object> map = new HashMap<>();
        map.put("money1", sendPriceService.getById(1).getMoney());
        map.put("money2", sendPriceService.getById(2).getMoney());
        String result = JsonUtil.obj2ApiJson(Result.successInfoApi(map, "priceInfo"));
        WebUtil.printApi(response, result);
    }

    /**
     * @api {post} /api/index/paperImageList 18、纸条背景图列表
     * @apiVersion 0.0.1
     * @apiName index.paperImageList
     * @apiGroup index
     *
     * @apiDescription 纸条背景图列表
     *
     * @apiParam   {Integer}   type                       类型，1=短叹，2=长吟    （必填）
     *
     * @apiSuccess {Object}    list
     * @apiSuccess {Integer}   list.id                    背景图ID
     * @apiSuccess {Integer}   list.type                  类型，1=短叹，2=长吟
     * @apiSuccess {String}    list.cover                 封面url
     * @apiSuccess {String}    list.name                  背景图名称
     * @apiSuccess {String}    list.num                   背景图编号
     * @apiSuccess {String}    list.money                 背景图价格
     *
     * @apiSuccessExample {json} Success-Response:
     * HTTP/1.1 200 OK
     * {
     *      "status":0,
     *      "msg":"",
     *      "data":{
     *          "list": [
     *              {
     *                  "id" : 1,
     *                  "type" : 1,
     *                  "cover" : "http://4.16.3.22:8080/images/cover.jpg",
     *                  "name" : "测试数据",
     *                  "num" : "512-259",
     *                  "money" : 1.5
     *              }
     *          ]
     *      }
     * }
     */
    @RequestMapping(value = "/paperImageList", method = RequestMethod.POST)
    public void paperImageList(HttpServletResponse response, Integer type) {
        if (null == type) {
            WebUtil.printApi(response, JsonUtil.obj2ApiJson(Result.failureApi(ErrorType.ERROR_NOT_PARAM)));
            return;
        }

        List<PaperImage> list = paperImageService.findListByType(type);
        String result = JsonUtil.obj2ApiJson(Result.successListApi(list));
        WebUtil.printApi(response, result);
    }
}
